clear all

/****************************************************************************************************
		
Replication file 1 out of 3 for:
"The Intractability of Islamist Insurgencies: Islamist Rebels and the Recurrence of Civil War"
Desirée Nilsson & Isak Svensson
International Studies Quarterly
Last updated: 20 April 2021
Note that dyadep 18502 has been replaced with 28502 due to an error in original termination data

***************************************************************************************************/


*To run the do-file you need to install the following:

*1. To generate summary statistics:
//ssc install unique, replace all

*2. To generate graphs:
//ssc install blindschemes, replace all
//set scheme plottig, permanently

*3. To generate tables: 
//ssc install outreg
//ssc install outreg2

****************************************************************************************************

use "Termination-data-ISQ.dta"
sort dyadid year

************************************************
* STSET FOR SURVIVAL ANALYSIS
************************************************

stset end_of_segment, id(dyadid) origin(time first_year_of_con) enter(time start_of_segment) failure(term==1) exit(time .)


************************************************
* DESCRIPTIVE STATISTICS
************************************************


*Islamist conflicts and termination
unique dyadid if islamist==1 | islamist==0 
*386
unique dyadid if islamist==1 
*64
unique dyadid if islamist==0
*322
unique dyadid if term==1 
*367


*Islamist conflicts and foreign fighters*
unique dyadid if foreignfighter==1 & islamist==1 
*30 out of 64, 47%
unique dyadid if islamist==1

unique dyadid if foreignfighter==1 & islamist==0
*54 out of 322, 17%
unique dyadid if islamist==0


*Islamist conflicts and govmilsupport*
unique dyadid if govmilsupport==1 & islamist==1 
* 28 out of 64, 44%
unique dyadid if islamist==1

unique dyadid if govmilsupport==1 & islamist==0 
* 48 out of 322, 15%
unique dyadid if islamist==0


*Leftist*
unique dyadid if leftist==1 //61
unique dyadid if leftist==0 //321


*Leftist and foreign fighters*
unique dyadid if foreignfighter==1 & leftist==1 
*11 out of 61, 18%
unique dyadid if leftist==1

unique dyadid if foreignfighter==1 & leftist==0 
*72 out of 321, 22%
unique dyadid if leftist==0


*Leftist and govmilsupport*
unique dyadid if govmilsupport==1 & leftist==1 
* 8 out of 61, 13%
unique dyadid if leftist==1 //

unique dyadid if govmilsupport==1 & leftist==0 
*69 out of 321, 21,5%
unique dyadid if leftist==0


************************************************
* CREATE LABELS
************************************************

label variable term "Termination"
label variable islamist "Islamist claim"
label variable territory "Territory"
label variable duration "Duration"
label variable intensitylevel "War"
label variable number_group "Number of groups"
label variable strongstart "Strong rebels"
label variable anostart "Anocracy"
label variable lngdppcstart "GDP per capita"
label variable lnpopstart "Population"
label variable muslimajstart "Muslim majority"
label variable oilstart "Oil"
label variable youthstartap "Youth bulge/adult pop."
label variable anocracy "Anocracy over time"
label variable lngdppc "GDP per capita over time"
label variable lnpop "Population over time"
label variable foreignfighter "Foreign fighters"
label variable govmilsupport "Government support"
label variable leftist "Leftist"
label variable nonislamistrel "Non-Islamist religious claims"
label variable muslimid "Muslim identity"
label variable secsup_govgov "Government secondary support"
label variable rebextpartdummy "Rebel support"


************************************************
* CONTROL VARIABELS
************************************************

global X1 territory strongstart oilstart youthstartap muslimajstart
global X2 _yrs _yrs_sq _yrs_cu


************************************************
* TABLE A1
************************************************

*Summary statistics*
su islamist territory strongstart oilstart youthstartap muslimajstart lngdppcstart anostart lnpopstart foreignfighter duration intensitylevel leftist term muslimid nonislamistrel anocracy lngdppc lnpop govmilsupport number_group secsup_govgov rebextpartdummy
//keep term islamist territory strongstart oilstart youthstartap muslimajstart lngdppcstart anostart lnpopstart foreignfighter duration intensitylevel leftist term muslimid nonislamistrel anocracy lngdppc lnpop govmilsupport number_group secsup_govgov rebextpartdummy
//outreg2 using appendix-A1.doc, replace sum(log) keep (term islamist territory strongstart oilstart youthstartap muslimajstart lngdppcstart anostart lnpopstart foreignfighter duration intensitylevel leftist muslimid nonislamistrel anocracy lngdppc lnpop govmilsupport number_group secsup_govgov rebextpartdummy)
//reload data after this line

************************************************
* TABLE 1
************************************************

*Model 1*     
stcox islamist $X1, cluster(dyadid) strata(order)  nolog
outreg using termination-t1.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox islamist $X1, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail


************************************************
* FIGURE 1
************************************************

*Kaplan meier graph with confidence intervals, strata not possible
sts graph, legend (cols(1)) by(islamist) ci 
*minor adjustments made manually, e.g.  set background region to grayscale 15, set labels*


************************************************
* TABLE 2
************************************************

*Model 1*
stcox islamist $X1 foreignfighter govmilsupport, cluster(dyadid) strata(order) nolog
outreg using termination-t2.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox islamist $X1 foreignfighter govmilsupport, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail


************************************************
* TABLE 3
************************************************

*Model 1*
stcox leftist $X1 govmilsupport foreignfighter, cluster(dyadid) strata(order) nolog
outreg using termination-t3.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox leftist $X1 govmilsupport foreignfighter, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail


************************************************************************************************************************************************************************************

****ROBUSTNESS****

************************************************************************************************************************************************************************************


************************************************
* TABLE A2
************************************************

//See do-file on recurrence//


************************************************
* TABLE A3
************************************************

*alternative survival models*

*Model 1* weibull instead of cox, without strata
streg islamist $X1, dist(weibull) cluster(dyadid) nolog
outreg using appendix-A3a.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

*streg islamist $X1, dist(weibull) cluster(dyadid) strata(order) nolog

*Model 2* exponential instead of cox, without strata
streg islamist $X1, dist(exponential) cluster(dyadid) nolog
outreg using appendix-A3b.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

streg islamist $X1, dist(exponential) cluster(dyadid) strata(order) nolog


************************************************
* TABLE A4 & A5
************************************************

//See do-file on recurrence//


************************************************
* TABLE A6
************************************************

//See separate dataset and do-file, two-year-gap//


************************************************
* TABLE A7a - Foreign fighters
************************************************

*Model 1*
gen islamistff=islamist*foreignfighter

stcox islamist $X1 islamistff foreignfighter govmilsupport, cluster(dyadid) strata(order) nolog
outreg using appendix-A7a-term.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox islamist $X1 islamistff foreignfighter govmilsupport, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail

*lrtest*
stcox i.islamist i.foreignfighter $X1 govmilsupport, strata(order) nolog 
estimates store main

stcox i.islamist##i.foreignfighter $X1 govmilsupport, strata(order) nolog 
estimates store inter

lrtest main

*wald*
stcox i.islamist##i.foreignfighter $X1 govmilsupport, strata(order) nolog 

test 1.islamist#0.foreignfighter=1.islamist#1.foreignfighter

*Model 2 and 3*

//See do-file on recurrence//


************************************************
* TABLE A7b - Foreign fighters is absent
************************************************

*Model 1, when Foreign Fighter is 0*
gen foreignfighter0=.
recode foreignfighter0 .=1 if foreignfighter==0
recode foreignfighter0 .=0 if foreignfighter==1
tab foreignfighter0 foreignfighter

gen islamistff0=islamist*foreignfighter0

stcox islamist $X1 islamistff0 foreignfighter0 govmilsupport, cluster(dyadid) strata(order) nolog
outreg using appendix-A7b-term.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

*Model 2 and 3*

//See do-file on recurrence//


************************************************
* TABLE A7c - Govmilsupport
************************************************

*Model 1*
gen islamistgovmil=islamist*govmilsupport

stcox islamist $X1 islamistgovmil govmilsupport foreignfighter, cluster(dyadid) strata(order) nolog
outreg using appendix-A7c-term.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox islamist $X1 islamistgovmil govmilsupport foreignfighter, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail

*lrtest*
stcox i.islamist i.govmilsupport $X1 foreignfighter, strata(order) nolog 
estimates store main

stcox i.islamist##i.govmilsupport $X1 foreignfighter, strata(order) nolog 
estimates store inter

lrtest main

*wald*
stcox i.islamist##i.govmilsupport $X1 foreignfighter, strata(order) nolog 

test 1.islamist#0.govmilsupport=1.islamist#1.govmilsupport

*Model 2 and 3*

//See do-file on recurrence//


************************************************
* TABLE A7d - Govmilsupport is absent
************************************************

*Model 1, when Govmil support is 1*
gen govmilsupport0=.
recode govmilsupport0 .=1 if govmilsupport==0
recode govmilsupport0 .=0 if govmilsupport==1
tab govmilsupport0 govmilsupport

gen islamistgovmil0=islamist*govmilsupport0

stcox islamist $X1 islamistgovmil0 govmilsupport0 foreignfighter, cluster(dyadid) strata(order) nolog
outreg using appendix-A7d-term.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox islamist $X1 islamistgovmil0 govmilsupport0 foreignfighter, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail


*Model 2 and 3*

//See do-file on recurrence//


************************************************
* TABLE A8
************************************************

*alternative measures of secondary support*

*Model 1*
stcox islamist $X1 secsup_govgov rebextpartdummy, cluster(dyadid) strata(order) nolog
outreg using appendix-A8a.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox islamist $X1 secsup_govgov rebextpartdummy, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail

*Model 2 and 3*

//See do-file on recurrence//


************************************************
* TABLE A9
************************************************

*gdp, population and anocracy*

*Model 1*
stcox islamist $X1 lngdppcstart lnpopstart, cluster(dyadid) strata(order) nolog
outreg using appendix-A9.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox islamist $X1 lngdppcstart lnpopstart, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail

*Model 2*
stcox islamist $X1 anostart, cluster(dyadid) strata(order) nolog
outreg using appendix-A9.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) merge

capture drop sch* sca*
stcox islamist $X1 anostart, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail

*Model 3*
stcox islamist $X1 lngdppc lnpop, cluster(dyadid) strata(order) nolog
outreg using appendix-A9.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) merge

capture drop sch* sca*
stcox islamist $X1 lngdppc lnpop, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail

*Model 4*
stcox islamist $X1 anocracy, cluster(dyadid) strata(order) nolog
outreg using appendix-A9.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) merge

capture drop sch* sca*
stcox islamist $X1 anocracy, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail


************************************************
* TABLE A10 and A11
************************************************

*gdp, population and anocracy*
//See do-file on recurrence//


************************************************
* TABLE A12
************************************************

*Model 1*
stcox leftist $X1, cluster(dyadid) strata(order) nolog
outreg using appendix-A12a.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox leftist $X1, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail

*Model 2*
stcox muslimid $X1, cluster(dyadid) strata(order) nolog
outreg using appendix-A12a.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) merge

capture drop sch* sca*
stcox muslimid $X1, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail

*Model 3*
stcox nonislamistrel $X1, cluster(dyadid) strata(order) nolog
outreg using appendix-A12a.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) merge

capture drop sch* sca*
stcox nonislamistrel $X1, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail


*Model 4-6*
//See do-file on recurrence//


************************************************
* TABLE A13
************************************************

//See do-file on recurrence//


************************************************
* TABLE A14
************************************************

*number_group*

*Model 1*
stcox islamist $X1 number_group, cluster(dyadid) strata(order) nolog
outreg using appendix-A14a.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox islamist $X1 number_group, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail


************************************************
* TABLE A15
************************************************

*duration and intensity*

*Model 1*
stcox islamist $X1 duration intensitylevel, cluster(dyadid) strata(order) nolog
outreg using appendix-A15a.doc, se var hr starlevels(10 5 1) sigsymbols(+,*,**) note (Robust standard errors in parentheses clustered on dyad.) replace

capture drop sch* sca*
stcox islamist $X1 duration intensitylevel, cluster(dyadid) strata(order) scaledsch(sca*) schoenfeld(sch*) nohr
stphtest, rank detail


************************************************
* TABLE A16
************************************************

//See do-file on recurrence//


************************************************************************************************************************************************************************************
************************************************************************************************************************************************************************************
